import * as actions from '../actions/index';

// 对页面prop 数据进行管理
export const initialState = {
  ip_whitelist_data: {},
  last_ip_whitelist_data: {},
  errors: {},
  isIPLoading: true,
};
const defaultAction = {
  type: 'doNothing',
};

export default function index(state = initialState, action = defaultAction) {
  switch (action.type) {
    case actions.RECEIVE_IP_WHITE_CHECK:
      return { ...state, ip_whitelist_data: action.data, isIPLoading: false };
    case actions.RECEIVE_LAST_IP_WHITE_CHECK:
      return { ...state, last_ip_whitelist_data: action.data, isLastIPLoading: false };
    case actions.UPDATE_DATA:
      return { ...state, ...action.data };
    case actions.RESET_DATA:
      return { ...initialState };
    case actions.SET_ERRORS:
      return {
        ...state,
        errors: {
          ...state.errors,
          ...action.errors,
        },
      };
    default:
      return state;
  }
}
